package cn.libiting.dateRange;


import cn.libiting.dateRange.utils.ThreadLocalUtil;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: wangxc
 * Date: 12-9-24
 * Time: 上午11:40
 * To change this template use File | Settings | File Templates.
 */
public enum DateRange {
    CURRENT_WEEK, LAST_WEEK,
    CURRENT_MONTH,LAST_MONTH,
    FIRST_QUARTER, SECOND_QUARTER, THIRD_QUARTER, FOURTH_QUARTER,
    CURRENT_QUARTER, LAST_QUARTER;


    public Date startDay() {
        return startDayImpl(getDate(), this);
    }

    public Date endDay() {
        return endDayImpl(getDate(), this);
    }


    static Date startDayImpl(Date date, DateRange type) {
        return dateIntervalInterface.startDay(date, type);
    }

    static Date endDayImpl(Date date, DateRange type) {
        return dateIntervalInterface.endDay(date, type);
    }
    private static cn.libiting.dateRange.DateIntervalInterface dateIntervalInterface = new DefaultDateIntervalInterface();

    public static Date getDate() {
        Date date = ThreadLocalUtil.getDateFrom();
        if (date == null) {
            date = new Date();
        }
        return  date;
    }
}
